<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="format-detection" content="email=no"/>
    <meta charset="UTF-8">
    <script type="text/javascript" th:src="@{${session.baseUrl}+'js/common.js'}"></script>
    <script th:src="@{${session.baseUrl}+'js/jquery.js'}"></script>
    <link th:href="@{${session.baseUrl}+'style/reset.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/base.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/header.css'}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" th:href="@{${session.baseUrl}+'style/orderMessage.css'}"/>
    <link th:href="@{${session.baseUrl}+'style/dialog.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/global.css'}" rel="stylesheet" type="text/css">
    <script th:src="@{${session.baseUrl}+'js/dialogbutton.js'}"></script>
    <script th:src="@{${session.baseUrl}+'js/dialog.js'}"></script>
    <title>订单信息</title>
    <style>
        .sub{
            width: 6.3rem;
            background: #2d9cff;
            display: block;
            margin: 0.3rem auto;
            line-height: 0.75rem;
            color: #fff;
            font-size: 0.26rem;
            text-align: center;
            border-radius: 0.1rem;
            cursor: pointer;
            -webkit-appearance: none;
        }
        #inputmoney{
            line-height: 0.7rem;
            padding-right: .30rem;
            padding-left: .30rem;
            margin-top: .20rem;
            margin-bottom: .20rem;
            background-color: #fff;
        }
        #error{
            padding-left: 0.3rem;
            font-size: 0.3rem;
            line-height: 0.4rem;
            padding-bottom: 0.3rem;
            font-weight: bold;
        }
    </style>
</head>
<body>
<header><span onclick="javascript:history.go(-1)"></span>订单信息</header>
<h1 style="font-size: 0.32rem;color: #323232;font-weight: bold;padding-top: 0.30rem;padding-left: 0.6rem;" th:text="${drafts.name}"></h1>

    <input type="hidden"  id="projectId" name="projectId" th:value="${drafts.id}">
    <input type="hidden"  id="projectName"  name="projectName" th:value="${drafts.name}">
    <input type="hidden"  id="memberId" name="memberId" th:value="${session.memberId}">
    <input type="hidden" th:value="${#numbers.formatDecimal(drafts.totalMoney-drafts.currentTotal,1,2)}" id="projectBalance"/>
    <input type="hidden" id="minMoney" th:value="${drafts.minMoney}">
    <input type="hidden" id="balance" th:value="${balance}">
<input type="hidden" th:value="${drafts.infoI}" name="infoI" id="infoI">

    <div class="pl30 pr30 bgwh">
        <div class="df jcsb aic pl30 pr30 bgwh mt20 all"><span>年化收益率：</span><b style="font-size: 0.4rem;color: red"  th:text="${#numbers.formatDecimal(100*drafts.rate,1,2)}+'%'"></b></div>
        <div class="df jcsb aic pl30 pr30 bgwh mt20 all"><span>剩余可认购金额：</span><b  th:text="${#numbers.formatDecimal(drafts.totalMoney-drafts.currentTotal,1,2)}"></b></div>
        <div class="df jcsb aic pl30 pr30 bgwh mt20 all"><span>最低认购金额：</span><b  th:text="${drafts.minMoney}"></b></div>
        <div class="df jcsb aic pl30 pr30 bgwh mt20 all"><span>可用余额：</span><b style="color: #0ba427" th:text="${balance}"></b></div>

        <div class="df jcsb aic pl30 pr30 bgwh mt20 all"><span>请输入投标金额:</span>
            <span></span>
        </div>
            <input id="inputmoney"  name="money" type="text" placeholder="不能小于最低认购金额" onfocus="qingchu()" />


             <div>
                <span id="error"></span>
             </div>
        </div>
    <div class="df jcsb aic pl30 pr30 bgwh mt20 all" style="font-weight: bold"><span>投标金额</span><span id="xianshi"><i>￥</i>0</span></div>
            <input class="sub" type="submit" onclick="queren()" value="提交订单"/>





<script type="text/javascript" th:inline="javascript">
    var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;

    var userInfoI = [[${infoI}]]
    
    function qingchu() {
         $("#error").html("");
    }

    function queren() {
        //验证是否登录
        var memberId = $("#memberId").val();
        //验证是否输入投资额
        var money = parseFloat($("#inputmoney").val());
        //验证投资额是否大于最低可投资金额
        var minMoney = parseFloat($("#minMoney").val());
        //验证投资额是否大于剩余可投资金额
        var projectBalance = parseFloat($("#projectBalance").val());
        //验证用户余额是否足够
        var memberBalance = parseFloat($("#balance").val());
        var span = $("#error");
        var projectInfoI = parseFloat($("#infoI").val());

        if (memberId == '' || memberId == null) {
            span.html('请登录后重试！').css('color', '#ff2525');
            return false;
        } else if (money <= 0 || money != money) {
            span.html('请输入正确的金额！').css('color', '#ff2525');
            return false;
        } else if (money < minMoney) {
            span.html('不能小于最低可认购金额！').css('color', '#ff2525');
            return false;
        } else if (money > projectBalance) {
            span.html('不能大于剩余可认购金额！').css('color', '#ff2525');
            return false;
        } else if (money > memberBalance) {
            span.html('余额不足，请充值！').css('color', '#ff2525');
            return false;
        } else if (projectInfoI != 2 && userInfoI != projectInfoI) {
            if (userInfoI == 0){
                span.html('该汇票为企业汇票！').css('color', '#ff2525');
            }
            if (userInfoI == 1){
                span.html('该汇票为个人汇票！').css('color', '#ff2525');
            }
            return false;
        }else {

            $('body').dailogbutton({type: 'success', title: '确认提交', discription: '是否确认提交？'},function(ret) {

                if(ret.index===0){

                    $.ajax({
                        url: basePath+"/memberOrder/add2",
                        contentType: 'application/json',
                        type: "POST",
                        dataType: "json",
                        data: JSON.stringify({
                            money: money,
                            memberBalance: memberBalance,
                            memberId: memberId,
                            projectId: $('#projectId').val(),
                            payStatus: 0,
                        }),
                        success: function (e) {
                            if (e.path!=''&&e.path!=null) {
                                window.location.href = basePath + '/wap/memberProject/topay?projectId=' + $('#projectId').val() + "&money=" + money + "&orderId=" + e.path;
                            }
                        }

                    })



                }else{
                    $.ajax({
                        url: basePath+"/memberOrder/add2",
                        contentType: 'application/json',
                        type: "POST",
                        dataType: "json",
                        data: JSON.stringify({
                            money: money,
                            memberBalance: memberBalance,
                            memberId: memberId,
                            projectId: $('#projectId').val(),
                            payStatus: 2,
                        }),
                        success: function (e) {

                            if (e.path!=''&&e.path!=null) {
                                $('body').dailog({type: 'primary', discription: '已取消，可在我的订单中查询'});
                                self.setInterval(function () {  // 这个方法是说在延迟3秒后执行大括号里的方法
                                    location.reload();   // 这个方法是刷新当前页面
                                }, 3000) //这里3000代表3秒
                            }
                        }
                    })
                }


            })

        }








       /* var b = confirm("是否确认购买");
        if (b == true) {
            opentest11();
        } else {
            $.ajax({
                url: "/memberOrder/add2",
                contentType: 'application/json',
                type: "POST",
                dataType: "json",
                data: JSON.stringify({
                    money: $('#money').val(),
                    memberBalance: $('#memberBalance').val(),
                    memberId: $('#memberId').val(),
                    projectId: $('#projectId').val(),
                    payStatus: 0,
                }),
                success: function (e) {
                    if (e.data) {
                        $('body').dailog({type: 'primary', discription: '已取消，可在我的订单中查询'});
                        self.setInterval(function () {  // 这个方法是说在延迟3秒后执行大括号里的方法
                            location.reload();   // 这个方法是刷新当前页面
                        }, 4000) //这里3000代表3秒
                    }
                }
            })
        }
*/






    }











    /*投资金额随着用户输入而更改*/
    $("#inputmoney").bind('input propertychange', function() {
        var number = $("#inputmoney").val();
        $("#xianshi").html('<i>￥</i>'+ number);
    });







</script>
</body>
</html>